import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/common/app_spaces.dart';
import 'package:finance_app/src/widgets/bottom_sheet/default_info_bottom_sheet.dart';
import 'package:finance_app/src/widgets/button/normal_button.dart';
import 'package:flutter/material.dart';

import 'default_bottom_sheet.dart';

showCancelSubscriptionSuccessBottomSheet(BuildContext context, String time) =>
    showGotItTipInfoBottomSheet(
        context,
        '''Your subscription has been
cancelled successfully''',
        [
          TextSpan(text: '''You will still be able to continue
adding transactions until $time''')
        ],
        null);

showTotalUsefulLifeTipInfoBottomSheet(BuildContext context,
        {VoidCallback onGotIt}) =>
    showGotItTipInfoBottomSheet(
        context,
        S.current.total_useful_life,
        [
          TextSpan(
              text: S.current
                  .the_system_has_provided_the_default__useful_life_for_the_selected_category_)
        ],
        S.current.any_changes_will_affect_the_tax_computation,
        onGotIt: onGotIt);

showUnableGeneratePayslipBottomSheet(BuildContext context,
        {VoidCallback onGotIt}) =>
    showGotItTipInfoBottomSheet(context, S.current.unable_to_generate_payslip,
        null, S.current.to_generate_payslip_please_fill_in,
        bulletsContent: [
          '• ${S.current.pass_type}',
          '• ${S.current.basic_salary}',
          '• ${S.current.no_of_working_days_per_week}',
          '• ${S.current.employment_type}',
          '• PR Start Date (if applicable)',
          '• SHG Type & Amount (if applicable)',
          '• Foreign Worker Levy (if applicable)',
        ],
        onGotIt: onGotIt);

showCOABalanceNotEqualInfoBottomSheet(BuildContext context,
        {VoidCallback onGotIt}) =>
    showGotItTipInfoBottomSheet(
        context,
        S.current.please_ensure_that_total_debit_equals_to_total_credit_amount,
        [
          TextSpan(
              text: S.current
                  .if_you_prefer_to_force_it_to_balance_now_please_enter_the_difference_amount_into_account),
          TextSpan(
              text: '"3110 Other Equity Items"',
              style:
                  TextStyle(fontWeight: FontWeight.bold, color: aceBlackColor)),
        ],
        S.current
            .note_future_revisit_to_this_account_is_necessary_for_identifying_the_difference,
        onGotIt: onGotIt);

showRecordFixedAssetSalesInfoBottomSheet(BuildContext context,
        {VoidCallback onGotIt}) =>
    showGotItTipInfoBottomSheet(
        context,
        S.current.record_fixed_asset_sales,
        null,
        S.current
            .to_save_this_moneyin_you_need_to_complete_the_sales_of_fixed_asset_form_first,
        onGotIt: onGotIt,
        gotBtnText: S.current.continue_to_form);

showRecordFixedAssetAdditionInfoBottomSheet(BuildContext context,
        {VoidCallback onGotIt}) =>
    showGotItTipInfoBottomSheet(
        context,
        S.current.record_fixed_asset_addition,
        null,
        S.current
            .to_save_this_expense_you_need_to_complete_the_new_fixed_asset_form_first,
        onGotIt: onGotIt,
        gotBtnText: S.current.continue_to_form);

/// rejected
showGotItTipBottomSheet(BuildContext context, String title,
        List<InlineSpan> content, String content2,
        {VoidCallback onGotIt,
        String gotBtnText,
        bool isDismissible = true,
        bool hasClosed = true}) =>
    showDefaultBottomSheet(
      context,
      child: _GotItInfoWidget(
        onGotIt: onGotIt,
        title: title,
        content: content,
        sureBtnText: gotBtnText,
        content2: content2,
      ),
      isScrollControlled: true,
      hasClosed: hasClosed,
      isDismissible: isDismissible,
    );

showGotItTipInfoBottomSheet(BuildContext context, String title,
        List<InlineSpan> content, String content2,
        {List<String> bulletsContent,
        VoidCallback onGotIt,
        bool isDismissible = true,
        bool hasClose = true,
        String gotBtnText}) =>
    showDefaultInfoBottomSheet(
      context,
      child: _GotItInfoWidget(
        onGotIt: onGotIt,
        title: title,
        content: content,
        sureBtnText: gotBtnText,
        content2: content2,
        bulletContents: bulletsContent,
      ),
      isScrollControlled: true,
      hasClose: hasClose,
      isDismissible: isDismissible,
    );

/// Fixed asset Cost Info
showFixedAssetCostInfoBottomSheet(BuildContext context,
        {VoidCallback onGotIt}) =>
    showDefaultBottomSheet(
      context,
      title: S.current.cost,
      child: _GotItInfoWidget(onGotIt: onGotIt, title: null, content: [
        TextSpan(
            text: S.current
                .for_gstregistered_users_the_amount_entered_has_to_be_exclusive_of_gst)
      ]),
    );

showSwitchFinancialYearInfoBottomSheet(BuildContext context,
        {VoidCallback onGotIt}) =>
    showDefaultBottomSheet(
      context,
      title: S.current.switch_financial_year,
      child: _GotItInfoWidget(onGotIt: onGotIt, title: null, content: [
        TextSpan(
            text: S.current
                .this_field_allows_you_to_access_previous_closed_financial_yearss_records)
      ]),
    );

class _GotItInfoWidget extends StatelessWidget {
  final VoidCallback onGotIt;
  final String title;
  final List<InlineSpan> content;
  final String content2;
  final List<String> bulletContents;
  final String sureBtnText;

  const _GotItInfoWidget(
      {Key key,
      this.onGotIt,
      this.sureBtnText,
      this.title,
      this.content,
      this.content2,
      this.bulletContents})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        if (title != null)
          Text(
            title,
            style: TextStyle(
              color: aceBlackColor,
              fontSize: getSp(22),
              fontWeight: FontWeight.w700,
              height: 24 / 22,
            ),
          ),
        if (content != null)
          Padding(
            padding: EdgeInsets.only(
                top: getDp(20), left: getDp(25), right: getDp(25)),
            child: Text.rich(
              TextSpan(
                children: content,
                style: TextStyle(
                  color: aceBlackColor,
                  fontSize: getSp(16),
                  fontWeight: FontWeight.w400,
                  height: 22 / 16,
                  fontFamily: "DinRoundPro",
                ),
              ),
              textAlign: TextAlign.center,
            ),
          ),
        if (content2 != null)
          Padding(
            padding: EdgeInsets.only(
                top: getDp(15), left: getDp(25), right: getDp(25)),
            child: Text(
              content2,
              textAlign: TextAlign.center,
              style: TextStyle(
                color: aceBlackColor,
                fontSize: getSp(16),
                fontWeight: FontWeight.w400,
                height: 22 / 16,
              ),
            ),
          ),
        if (bulletContents != null)
          Padding(
            padding: EdgeInsets.only(top: getDp(15)),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: bulletContents
                  .map((e) => Padding(
                        padding: const EdgeInsets.only(top: 8.0),
                        child: Text(e,
                            style: TextStyle(
                              color: aceBlackColor,
                              fontSize: getSp(16),
                              fontWeight: FontWeight.w400,
                              height: 22 / 16,
                            )),
                      ))
                  .toList(),
            ),
          ),
        AppSpaces.h30,
        NormalButton(
          title: sureBtnText ?? S.current.got_it,
          onTap: onGotIt ??
              () {
                Navigator.of(context).pop(true);
              },
        ),
      ],
    );
  }
}
